from django.contrib.auth.models import AbstractUser
from django.db import models
from utils.common_base_models import BaseModel


# Create your models here.
class User(AbstractUser):
    """
    用户
    """
    sex_choices = (
        (1, '男'),
        (2, '女'),
        (3, '保密')
    )
    mobile = models.CharField(verbose_name='手机号', max_length=11, null=True, blank=True)
    # 需要pillow包的支持

    icon = models.CharField(verbose_name='头像',
                            default='https://thirdwx.qlogo.cn/mmopen/vi_32/5UHydV26CHYIs1cmOWQHklFoWveNzxkumr8bwuSCdIGCdLg0Z0GpuicRZkEgZt0jRicoV0YiaHk53XCqvM9W5Bh1w/132',
                            max_length=225)

    id_card = models.CharField(verbose_name='身份证', max_length=32, unique=True, null=True, blank=True)
    addr = models.TextField(verbose_name='地址', null=True, blank=True)
    desc = models.TextField(verbose_name='个人简介', null=True, blank=True)
    sex = models.SmallIntegerField(verbose_name='性别', choices=sex_choices, default=1)
    category = models.ForeignKey(to='Category', on_delete=models.CASCADE, null=True, blank=True, related_name='c_u',
                                 db_constraint=False)
    name = models.CharField(verbose_name='昵称', max_length=32, unique=True, null=True, blank=True)

    class Meta:
        db_table = 'youzhu_user'  # 指定表名
        verbose_name = '用户表'  # 后台管理看到的中文
        verbose_name_plural = verbose_name

    def __str__(self):  # 打印对象，显示的
        return self.username


class Photo(BaseModel):
    """
    照片
    """
    # title = models.CharField(max_length=16, unique=True, verbose_name='名称')
    image = models.ImageField(upload_to='photo', verbose_name='图片')
    qiniu_link = models.CharField(max_length=255, verbose_name='七牛云链接',null=True, blank=True,)
    userinfo = models.ForeignKey(to='User', on_delete=models.CASCADE, null=True, blank=True, related_name='p_u',
                                 db_constraint=False)

    class Meta:
        db_table = 'youzhu_photo'
        verbose_name_plural = '照片墙'


class Category(BaseModel):
    """
    标签
    """
    color_choices = (
        (1, "MediumTurquoise"),
        (2, "Orange"),
        (3, "DarkGreen"),
    )
    title_choices=(
        (1, "白银会员"),
        (2, "黄金会员"),
        (3, "钻石会员"),
    )
    title = models.CharField(max_length=16,choices=title_choices)
    color = models.CharField(max_length=16, choices=color_choices, default=2)
